package org.hypnus.e.tag;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.BodyTag;
import javax.servlet.jsp.tagext.BodyTagSupport;

import org.hypnus.e.sub.EDataset;
import org.hypnus.e.sub.EField;
import org.hypnus.e.util.DataType;
import org.hypnus.e.util.TagUtil;

public class FieldTag extends BodyTagSupport {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private String id;

	private String name;

	private String datatype = DataType.STRING ;

	private String format ;
	
	private String value ;
	
	public String getValue() {
		return value;
	}

	public void setValue(String value) {
		this.value = value;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getDatatype() {
		return datatype;
	}

	public void setDatatype(String datatype) {
		this.datatype = datatype;
	}

	public String getFormat() {
		return format;
	}

	public void setFormat(String format) {
		this.format = format;
	}

	@Override
	public int doEndTag() throws JspException {
		return BodyTag.EVAL_PAGE ;
	}

	@Override
	public int doStartTag() throws JspException {
		
		DatasetTag parent = (DatasetTag) findAncestorWithClass(this, EDataset.class)  ;
		
		EDataset dst = TagUtil.getInstance().getEContext(pageContext).getDst(parent.getName()) ;
		EField fld = new EField() ;
		fld.setDataType(this.datatype ) ;
		fld.setId(this.getId()) ;
		fld.setName(this.name ) ;
		fld.setValue(this.getValue() ) ;
		fld.setFormat(this.getFormat() ) ;
		dst.addField(fld) ;
		return BodyTag.EVAL_BODY_INCLUDE;
	}

	
	
}
